package com.qf.core.response;


import lombok.Data;

import java.io.Serializable;

/**
 * @Author: sin
 * @Date: 2025/5/5 14:19
 * @Description: 封装自定义响应结果
 **/
@Data
public class ResponseResult <T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 响应状态码
     */
    private int code;

    /**
     * 响应消息
     */
    private String msg;

    /**
     * 响应数据
     */
    private T data;

    /**
     * 成功响应封装
     */
    public static <T> ResponseResult<T> success(T data) {
        ResponseResult<T> response = new ResponseResult<>();
        response.setCode(ResponseCode.SUCCESS.getCode());
        response.setMsg(ResponseCode.SUCCESS.getDesc());
        response.setData(data);
        return response;
    }

    public static <T> ResponseResult<T> success() {
        ResponseResult<T> response = new ResponseResult<>();
        response.setCode(ResponseCode.SUCCESS.getCode());
        response.setMsg(ResponseCode.SUCCESS.getDesc());
        return response;
    }

    public static <T> ResponseResult<T> success(String msg, T data) {
        ResponseResult<T> response = new ResponseResult<>();
        response.setCode(ResponseCode.SUCCESS.getCode());
        response.setMsg(msg);
        response.setData(data);
        return response;
    }

    /**
     * 失败响应封装
     */
    public static <T> ResponseResult<T> fail(String msg) {
        ResponseResult<T> response = new ResponseResult<>();
        response.setCode(ResponseCode.ERROR.getCode());
        response.setMsg(msg);
        return response;
    }
    public static <T> ResponseResult<T> fail(Integer code, String msg) {
        ResponseResult<T> response = new ResponseResult<>();
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }
}
